home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWGadgts / Sources / FWPushBu.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.7 KB  |  306 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPushBu.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPUSHBU_H
  13. #include "FWPushBu.h"
  14. #endif
  15.  
  16. #ifndef FWFRAME_H
  17. #include "FWFrame.h"
  18. #endif
  19.  
  20. #ifndef FWPART_H
  21. #include "FWPart.h"
  22. #endif
  23.  
  24. // ----- OS Layer -----
  25.  
  26. #ifndef FWEVENT_H
  27. #include "FWEvent.h"
  28. #endif
  29.  
  30. #ifndef FWRRCSHP_H
  31. #include "FWRRcShp.h"
  32. #endif
  33.  
  34. #ifndef FWODGEOM_H
  35. #include "FWODGeom.h"
  36. #endif
  37.  
  38. // ----- Foundation Includes -----
  39.  
  40. #ifndef FWSTREAM_H
  41. #include "FWStream.h"
  42. #endif
  43.  
  44. // ----- OpenDoc Includes -----
  45.  
  46. #ifndef SOM_ODSession_xh
  47. #include <ODSessn.xh>
  48. #endif
  49.  
  50. #ifndef SOM_ODFacet_xh
  51. #include <Facet.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODTransform_xh
  55. #include <Trnsform.xh>
  56. #endif
  57.  
  58. //========================================================================================
  59. // Runtime Informations
  60. //========================================================================================
  61.  
  62. #if FW_LIB_EXPORT_PRAGMAS
  63. #pragma lib_export on
  64. #endif
  65.  
  66. #ifdef FW_BUILD_MAC
  67. #pragma segment fwgadgts
  68. #endif
  69.  
  70. FW_DEFINE_CLASS_M1(FW_CPushButton, FW_CButton)
  71. FW_REGISTER_ARCHIVABLE_CLASS(FW_LPushButton, FW_CPushButton, FW_CPushButton::Read, FW_CGadget::Write)
  72.  
  73. //========================================================================================
  74. // CLASS FW_CPushButton
  75. //========================================================================================
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // FW_CPushButton::FW_CPushButton
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_CPushButton::FW_CPushButton(Environment* ev, 
  82.                                FW_CView* container, ODID id,
  83.                                const FW_CRect& bounds,
  84.                                const FW_CString& label) :
  85.     FW_CButton(ev, container, id, bounds),
  86.     fIsDefault(FALSE),
  87.     fButtonHelper(NULL)
  88. {
  89.     
  90. #ifdef FW_BUILD_MAC
  91.     fButtonHelper = new FW_CPrivMacPushButtonHelper
  92.                                 (ev, FW_TYPEID_FROM_TYPE(FW_CPrivMacPushButtonHelper), this);
  93. #endif
  94.  
  95. #ifdef FW_BUILD_WIN
  96.     fButtonHelper = new FW_CPrivWinPushButtonHelper
  97.                                 (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinPushButtonHelper), this);
  98. #endif
  99.  
  100.     fButtonHelper->SetText(label);
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_CPushButton::FW_CPushButton
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_CPushButton::FW_CPushButton(Environment* ev, 
  108.                                FW_CReadableStream& archive) :
  109.     FW_CButton(ev, archive)
  110. {
  111. #ifdef FW_BUILD_MAC
  112.     fButtonHelper 
  113.         = new FW_CPrivMacPushButtonHelper
  114.             (ev, FW_TYPEID_FROM_TYPE(FW_CPrivMacPushButtonHelper), this);
  115. #endif
  116.  
  117. #ifdef FW_BUILD_WIN
  118.     fButtonHelper = new FW_CPrivWinPushButtonHelper
  119.                                 (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinPushButtonHelper), this);
  120. #endif
  121.  
  122.     FW_CDynamicString label;
  123.  
  124.     archive >> fIsDefault;
  125.     FW_CStringArchiver::Read(archive, label);
  126.     
  127.     fButtonHelper->SetText(label);
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // FW_CPushButton::~FW_CPushButton
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_CPushButton::~FW_CPushButton()
  135. {
  136.     delete fButtonHelper;
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // FW_CPushButton::LocationChanged
  141. //----------------------------------------------------------------------------------------
  142.  
  143. void FW_CPushButton::LocationChanged(Environment* ev, const FW_CPoint &oldLocation)
  144. {
  145. FW_UNUSED(oldLocation);
  146.  
  147. #ifdef FW_BUILD_WIN
  148.     FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
  149.     
  150.     FW_SPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
  151.     FW_SPlatformPoint wndSize = fc.ContentToCanvas(GetSize(ev).x, GetSize(ev).y);
  152.     fButtonHelper->Move(wndLocation, wndSize);
  153. #endif
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // FW_CPushButton::SizeChanged
  158. //----------------------------------------------------------------------------------------
  159.  
  160. void FW_CPushButton::SizeChanged(Environment* ev, const FW_CPoint &oldSize)
  161. {
  162. FW_UNUSED(oldSize);
  163.  
  164. #ifdef FW_BUILD_WIN
  165.     FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
  166.     
  167.     FW_SPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
  168.     FW_SPlatformPoint wndSize = fc.ContentToCanvas(GetSize(ev).x, GetSize(ev).y);
  169.     fButtonHelper->Move(wndLocation, wndSize);
  170. #endif
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // FW_CPushButton::Draw
  175. //----------------------------------------------------------------------------------------
  176.  
  177. void FW_CPushButton::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  178. {
  179. #ifdef FW_BUILD_MAC
  180.     FW_CViewContext gc(ev, this, facet, invalidShape);
  181.  
  182.     ODPlatformWindow window = gc.GetFacet()->GetWindow(ev)->GetPlatformWindow(ev);
  183.  
  184.     FW_SPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
  185.     FW_SPlatformPoint qdSize;
  186.     GetSize(ev).AsPlatformPoint(qdSize);
  187.     fButtonHelper->Draw(window, qdPoint, qdSize);
  188.  
  189.     if (fIsDefault)
  190.     {
  191.         // Draw the standard default button border
  192.         
  193.         FW_CFixed buttonOval = FW_IntToFixed(2) + GetSize(ev).y.Half();
  194.         FW_CRoundRectShape::RenderRoundRect(
  195.             gc,
  196.             FW_CRect(FW_kZeroPoint, GetSize(ev)),
  197.             FW_CPoint(buttonOval, buttonOval),
  198.             FW_kFrame,
  199.             FW_kNormalInk,
  200.             FW_PStyle(FW_IntToFixed(3)));
  201.     }
  202. #endif
  203.  
  204. #ifdef FW_BUILD_WIN
  205.     // Windows handles updating controls automatically
  206. #endif
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // FW_CPushButton::DoMouseDown
  211. //----------------------------------------------------------------------------------------
  212.  
  213. FW_Boolean FW_CPushButton::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  214. {
  215. // This code is duplicated for in each control class, think about moving it to the
  216. // control helpers, and maybe making the owner of helpers be gadgets. [AMB]
  217.  
  218. #ifdef FW_BUILD_MAC
  219.     ODFacet* odFacet = theMouseEvent.GetFacet(ev);
  220.     FW_CViewContext gc(ev, this, odFacet);
  221.     
  222.     FW_CPoint canvasWhere = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kWindow);
  223.     
  224.     {
  225.         // Take into account the origin offset for pattern alignment. [AMB]
  226.         FW_CAcquiredODTransform aqTransform(odFacet->CreateTransform(ev));
  227.  
  228.         ODPlatformCanvas plfmCanvas = gc.GetPlatformCanvas();
  229.         FW_CPoint offset(
  230.             FW_IntToFixed(plfmCanvas->portRect.left),
  231.             FW_IntToFixed(plfmCanvas->portRect.top));
  232.         
  233.         ODPoint odOffset = offset;
  234.         aqTransform->MoveBy(ev, &odOffset);
  235.         
  236.         canvasWhere.Transform(ev, aqTransform);
  237.     }
  238.  
  239.     FW_SPlatformPoint qdControlPosition = gc.LogicalToDevice(FW_kZeroPoint);
  240.     FW_SPlatformPoint qdWhere;
  241.     canvasWhere.AsPlatformPoint(qdWhere);
  242.     ODPlatformWindow window = odFacet->GetWindow(ev)->GetPlatformWindow(ev);    
  243.     
  244.     FW_SPlatformPoint qdSize;
  245.     GetSize(ev).AsPlatformPoint(qdSize);
  246.  
  247.     return fButtonHelper->MouseDown(window, qdWhere, qdControlPosition, qdSize);
  248. #endif
  249.  
  250. #ifdef FW_BUILD_WIN
  251.     // Windows handles mouse events automatically
  252.     return FALSE;
  253. #endif
  254. }
  255.  
  256. //----------------------------------------------------------------------------------------
  257. // FW_CPushButton::SetDefault
  258. //----------------------------------------------------------------------------------------
  259.  
  260. void FW_CPushButton::SetDefault(Environment* ev, FW_Boolean isDefault)
  261. {
  262.     if (isDefault != fIsDefault)
  263.     {
  264.         fIsDefault = isDefault;
  265.         fButtonHelper->MakeDefaultButton(fIsDefault);
  266.     }
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. // FW_CPushButton::ButtonPressed
  271. //----------------------------------------------------------------------------------------
  272.  
  273. void FW_CPushButton::ButtonPressed(Environment* ev)
  274. {
  275.     // ----- Notify interested parties of that the button was pressed
  276.     
  277.     FW_CButtonPressedNotification notification(FW_CInterest(this, GetButtonPressedNotificationToken(ev)),
  278.                                                GetIdentifier(ev), 1);
  279.     Notify(notification);
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    FW_CPushButton::Flatten
  284. //----------------------------------------------------------------------------------------
  285.  
  286. void FW_CPushButton::Flatten(FW_CWritableStream& archive) const
  287. {
  288.     FW_CDynamicString label;
  289.     fButtonHelper->GetText(label);
  290.         
  291.     FW_CGadget::Flatten(archive);
  292.  
  293.     archive << fIsDefault;
  294.     FW_CStringArchiver::Write(archive, label);
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. //    FW_CPushButton::Read
  299. //----------------------------------------------------------------------------------------
  300.  
  301. void* FW_CPushButton::Read(FW_CReadableStream& archive)
  302. {
  303.     Environment* ev = ::somGetGlobalEnvironment();
  304.     return new FW_CPushButton(ev, archive);
  305. }
  306.